package com.kzj.common.util;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.kzj.common.properties.NoteProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SMSUtils2 {
	@Autowired
	NoteProperties noteProperties;
    public void sendMessage(String phone,String code){
		DefaultProfile profile = DefaultProfile.getProfile(noteProperties.getRegionId(), noteProperties.getAccessKeyId(), noteProperties.getAccessKeySecret());
		IAcsClient client = new DefaultAcsClient(profile);

		SendSmsRequest request = new SendSmsRequest();
		request.setSysRegionId(noteProperties.getRegionId());
		request.setPhoneNumbers(phone);
		request.setSignName(noteProperties.getSignName());
		request.setTemplateCode(noteProperties.getTemplateCode());
		request.setTemplateParam("{\"code\":\""+code+"\"}");
		try {
			SendSmsResponse response = client.getAcsResponse(request);
			System.out.println(response.getMessage());
			System.out.println(response.getCode());
			System.out.println("短信发送成功");
		}catch (ClientException e) {
			e.printStackTrace();
		}
	}
}
